﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ConsoleApplication
{
    class intArray
    {

        #region Array

        //  linear array

        public static void getLinearArray()
        {
            int[] iArray = { 1, 2, 3, 4, 5 };
            int[] iArray2 = new int[2];
            iArray2[0] = 11;
            iArray2[1] = 22;

            foreach (int i in iArray)
            {
                Console.WriteLine("iArray: {0}", i);
            }

            foreach (int i in iArray2)
            {
                Console.WriteLine("iArray2: {0}", i);
            }
            Console.ReadKey();
        }

        //  two-dimensional array

        public static void get2Array()
        {
            int[,] iArray = { { 1, 2, 3, 4, 5 }, { 2, 3, 4, 5, 6 }, { 3, 4, 5, 6, 7 } };
            foreach (int i in iArray)
            {
                Console.WriteLine("iArray: {0}", i);
            }
            Console.ReadKey();
        }

        //  arrays in an array
        //  using System.Diagnostics namespace with methods - Debug.WriteLine() / Trace.WriteLine().

        public static void getArrayInArray()
        {
            //  define the main Array which include 2 child int[].
            int[][] iArray = new int[2][];

            //  initialize the 2 child int[]. 
            //  NOTE: they can be the different array length.
            iArray[0] = new int[2];     //  length = 2
            iArray[1] = new int[5];     //  length = 5

            Common.InitializeAnArray(iArray[0]);
            Common.InitializeAnArray(iArray[1]);

            //  print the main Array values.
            //  NOTE:   need to use nested foreach statements to get all the values.
            Debug.WriteLineIf(true, string.Format("--------Start to write the int[{0}][].", iArray.Length));
            foreach (int[] iarr in iArray)
            {
                Trace.WriteLineIf(true, string.Format("--------Start to write the int[{0}].", iarr.Length));
                foreach (int i in iarr)
                {
                    Console.WriteLine("iArray: {0}", i);
                }
            }
            Console.ReadKey();
        }
        
       #endregion

    }
}
